import type { TableColumn } from '@/components/core/dynamic-table';

export type TableListItem = API.CaseApprovePageResultItem;
export type TableColumnItem = TableColumn<TableListItem>;

let nodeStatusList = [
  {
    label: '全部',
    value: -1,
  },
  {
    label: '待审批',
    value: 1,
  },
  {
    label: '同意',
    value: 2,
  },
  {
    label: '不同意',
    value: 3,
  },
];

const caseNodeStatus = (val) => {
  switch (val) {
    case 1:
      return '待审批';
    // return '-';
    case 2:
      return '同意';
    case 3:
      return '不同意';
    default:
      return '-';
  }
};

const caseTextColor = (val) => {
  switch (val) {
    case 1:
      return 'color: #F5820F';
    case 2:
      return 'color: #09B840';
    case 3:
      return 'color: #E22C4C';
    default:
      return 'color: #999999';
  }
};

const caseStatus = (val) => {
  switch (val) {
    case 1:
      return '立案';
    case 2:
      return '调查取证';
    case 3:
      return '案件处理';
    case 4:
      return '结案归档';
    case 5:
      return '案件终止';
    case 6:
      return '已结束';
    default:
      return '-1';
  }
};

const caseTextColor2 = (val) => {
  switch (val) {
    case 1:
      return 'color: #10A0AD';
    case 2:
      return 'color: #F5820F';
    case 3:
      return 'color: #1677FF';
    case 4:
      return 'color: #363687';
    case 5:
      return 'color: #E22C4C';
    case 6:
      return 'color: #09B840';
    default:
      return 'color: #999999';
  }
};

const checkerName = (sponsor, organizer) => {
  if (sponsor && organizer) {
    return sponsor + ',' + organizer;
  } else if (sponsor == '') {
    return organizer;
  } else if (organizer == '') {
    return sponsor;
  }
};

export const baseColumns: TableColumnItem[] = [
  {
    title: '关键词',
    dataIndex: 'keyword',
    hideInTable: true,
    searchField: 'keyword',
    formItemProps: {
      labelWidth: 55,
      componentProps: () => {
        return {
          placeholder: '可输入单位名称、案件编号搜索',
          autocomplete: 'off',
          disabledLabelWidth: true,
        };
      },
    },
  },
  {
    title: '案件编号',
    width: 160,
    align: 'left',
    dataIndex: 'caseCode',
    hideInSearch: true,
  },
  {
    title: '单位名称',
    width: 160,
    dataIndex: 'placeName',
    hideInSearch: true,
  },
  // {
  //   title: '简要案情',
  //   width: 160,
  //   dataIndex: 'caseBrief',
  //   hideInSearch: true,
  // },
  {
    title: '审批状态',
    width: 120,
    dataIndex: 'nodeStatus',
    resizable: true,
    formItemProps: {
      component: 'Select',
      componentProps: () => ({
        options: nodeStatusList,
      }),
      defaultValue: -1,
    },
    customRender: ({ record }) => (
      <div style={caseTextColor(record.nodeStatus)}>{caseNodeStatus(record.nodeStatus)}</div>
    ),
  },
  {
    title: '案件状态',
    width: 120,
    dataIndex: 'status',
    hideInSearch: true,
    customRender: ({ record }) => (
      <div style={caseTextColor2(record.status)}>{caseStatus(record.status)}</div>
    ),
  },
  {
    title: '执法人员',
    dataIndex: 'checkerName',
    width: 120,
    hideInSearch: true,
    customRender: ({ record }) => checkerName(record.sponsor, record.organizer),
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 120,
    hideInSearch: true,
  },
];
